package wechat.util;

import java.util.UUID;

import wechat.util.crypto.CryptoUtil;

public class WechatUtil {
	public static String getNonceStr() {
		UUID uuid = UUID.randomUUID();
		return uuid.toString().replace("-", "");
	}
	
	public static String signJS(String jsticket,String noncestr,String timestamp,String url) {
		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append("jsapi_ticket=");
		stringBuffer.append(jsticket);
		stringBuffer.append("&");
		stringBuffer.append("noncestr=");
		stringBuffer.append(noncestr);
		stringBuffer.append("&");
		stringBuffer.append("timestamp=");
		stringBuffer.append(timestamp);
		stringBuffer.append("&");
		stringBuffer.append("url=");
		stringBuffer.append(url);
		
		String str = stringBuffer.toString();
		return CryptoUtil.getSha1(str);
	}
}
